package com.hs.user.controller;


import com.hs.user.bean.User;
import com.hs.user.dto.BerthDto;
import com.hs.user.dto.ParkingDto;
import com.hs.user.service.IUserService;
import com.hs.common.api.dto.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author Lin GongZi
 * @since 2022-07-20
 * 登陆服务
 */
@RestController
@RequestMapping("/user")
@Api("用户端")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 登陆服务
     * @param
     * @return
     */
    @PostMapping()
    @ApiOperation("用户登陆")
    public ResultVo login(@RequestBody @Validated User user){
        ResultVo token = userService.login(user);

        return token;
    }

    /**
     * 泊车服务
     * @return
     */
    @GetMapping("/auth/{berthId}")
    @ApiOperation("泊车服务")
    public ResultVo parking(@PathVariable("berthId") @Validated Long berthId,HttpServletRequest request) throws ParseException {
        ParkingDto parkingDto = userService.parking(berthId,request);
        return new ResultVo(parkingDto);
    }

    /**
     * 车位搜索
     */
    @GetMapping("/auth")
    @ApiOperation("车位搜索")
    public ResultVo berthSearch(@RequestParam("currentLongitude") Double currentLongitude,@RequestParam("currentLatitude") Double currentLatitude){
        List<BerthDto> list = userService.berthSearch(currentLongitude,currentLatitude);
        return new ResultVo(list);
    }

    /**
     * 停车订单显示
     */
    @PostMapping("/auth")
    @ApiOperation("停车订单显示")
    public  ResultVo parkingOrder(String licensePlate){
        return userService.parkingOrder(licensePlate);
    }

    /**
     * 停车缴费
     */
    @PutMapping("/auth")
    @ApiOperation("停车缴费")
    public ResultVo payParking(Long orderId){
        return userService.payParking(orderId);
    }

    /**
     * 车辆绑定
     */
    @PostMapping("/auth/binding")
    @ApiOperation("车辆绑定")
    public ResultVo vehicleBinding(String licensePlate,String plateType,HttpServletRequest request){
        return userService.vehicleBinding(licensePlate,plateType,request);
    }


}

